package com.qf.config;

import com.qf.Constant.RabbitMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Date: 2021/07/28/20:13
 * @Description:
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange(RabbitMqConstant.ORDER_EXCHANGE,true,false);
    }
    @Bean
    public TopicExchange dlxExchage(){
        return new TopicExchange(RabbitMqConstant.STOCK_DLX_EXCHANGE,true,false);
    }
    @Bean
    public Queue stockQueue(){
        Map<String,Object> map=new HashMap<>();
        map.put("x-dead-letter-exchange",RabbitMqConstant.STOCK_DLX_EXCHANGE);
        map.put("x-dead-letter-routing-key","des.*");
        map.put("x-message-ttl",1000*10*12);
        return new Queue(RabbitMqConstant.STOCK_QUEUE,true,false,false,map);
    }
    @Bean
    public Queue dlxQueue(){
        return new Queue(RabbitMqConstant.STOCK_DLX_QUEUE,true,false,false);
    }
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(stockQueue()).to(orderExchange()).with("order.*");
    }
    @Bean
    public Binding dlxBinding(){
        return BindingBuilder.bind(dlxQueue()).to(dlxExchage()).with("des.*");
    }
}
